package com.Controller;

import com.Service.CategoryService;
import com.Service.GoodsService;
import com.Utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@CrossOrigin
@RestController
@RequestMapping("/Goods")
public class GoodsController {
    @Autowired
    GoodsService goodsService;
    @PostMapping("/findCategoryGoods")
    public R findAllCategory(@RequestBody Map<String,String> Map_All){
        int categoryId= Integer.parseInt(Map_All.get("categoryId"));
        return new R(true,goodsService.findCategoryGoods(categoryId));
    }
    @PostMapping("/updataCategoryGoods")
    public R updataCategoryGoods(@RequestBody Map<String,String> Map_All){
        int goodsId= Integer.parseInt(Map_All.get("goodsId"));
        String goodsName= Map_All.get("goodsName");
        String goodsContent= Map_All.get("goodsContent");
        String money= Map_All.get("money");
        String categoryId=Map_All.get("categoryId");
        return new R(true,goodsService.updataCategoryGoods(categoryId,goodsId,goodsName,goodsContent,money));
    }
    @PostMapping("/delCategoryGoods")
    public R delCategoryGoods(@RequestBody Map<String,String> Map_All){
        int goodsId= Integer.parseInt(Map_All.get("goodsId"));
        return new R(true,goodsService.delCategoryGoods(goodsId));
    }
    @PostMapping("/addCategoryGoods")
    public R addCategoryGoods(@RequestBody Map<String,String> Map_All){
        int categoryId= Integer.parseInt(Map_All.get("categoryId"));
        String goodsName= Map_All.get("goodsName");
        String goodsContent= Map_All.get("goodsContent");
        String money= Map_All.get("money");
        return new R(true,goodsService.addCategoryGoods(categoryId,goodsName,goodsContent,money));
    }
}
